<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>创建管理员</title>
    <link rel="stylesheet" href="./layui/css/layui.css">
    <link rel="stylesheet" href="./css/index.css">
    <link rel="Shortcut Icon" href="cachet.ico">
    <script src="./js/jquery.min.js"></script>
    <script src="./js/addimg.js"></script>
</head>
<body class="layui-layout-body">
   <div class="layui-body">
        <!-- 内容主体区域 -->
        <div class="body_right">
            <h4 class="nav_title">公司添加</h4>
            <ul class="create_iconbox">
                <li>
                    <i class="icon_top1 icon"></i>
                    <span>填写公司信息</span>
                </li>
                <li>
                    <i class="icon_top4 icon"></i>
                    <span>创建管理员账户</span>
                </li>
                <li>
                    <i class="icon_top3 icon"></i>
                    <span>账户开通</span>
                </li>
                <li class="line"></li>
            </ul>
            <div class="layui-form create_boxform" >
            		<form class="layui-form">
            		<input type="hidden" name="companyId" value="${company.companyId}">
                <div class="layui-form-item">
                    <label class="layui-form-label ">管理员姓名:</label>
                    <div class="layui-input-inline">
                        <input type="text" id="name" name="name" required="" lay-verify="name"  autocomplete="off" class="layui-input" placeholder="请输入管理员姓名">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">身份证号:</label>
                    <div class="layui-input-inline">
                        <input type="text" id="idcard" name="idcard" required="" lay-verify="idcard" autocomplete="off" class="layui-input" placeholder="请输入身份证号">
                    </div>
                </div>
                <div class="layui-form-item">
                        <label class="layui-form-label">身份证照片:</label>
                        <div class="layui-input-inline add_mebtn">
                             <div class="user-file-img upfile"  lay-data="{url: '/admin/upload/fileupload.htm?module=idcard',showImgId:'frontImg',inputId:'idcardFront'}">
	                    			<img src="" alt="" id="frontImg"/>
	                    		</div>
	                    		<input type="hidden" name="idcardFront" id="idcardFront" value="" class="user-file-input"/>
                            <p class="add_titps">正面照</p>
                        </div>
                        <div class="layui-input-inline add_mebtn">
                            <div class="user-file-img upfile" lay-data="{url: '/admin/upload/fileupload.htm?module=idcard',showImgId:'backImg',inputId:'idcardBack'}">
		                    		<img src="" alt="" id="backImg"/>
		                    </div>
		                    <input type="hidden" name="idcardBack" id="idcardBack" value="" class="user-file-input"/>
		                    <p class="add_titps">反面照</p>
                        </div>
                </div>
                <div class="layui-form-item">
                        <label class="layui-form-label">联系电话:</label>
                        <div class="layui-input-inline">
                            <input type="text" id="telephone" name="telephone" lay-verify="telephone" autocomplete="off" class="layui-input" placeholder="请输入联系电话">
                        </div>
                </div>
                <div class="layui-form-item">
                        <label class="layui-form-label">联系手机:</label>
                        <div class="layui-input-inline">
                            <input type="text"  id="mobile"  name="mobile" lay-verify="mobile" autocomplete="off" class="layui-input" placeholder="请输入联系手机号">
                            <p class="add_titps text-left">联系电话或联系手机选填一项</p>
                        </div>
                </div>
                <div class="layui-form-item">
                        <label class="layui-form-label">登陆账户:</label>
                        <div class="layui-input-inline">
                            <input type="text" id="username" name="username" required="" lay-verify="username" autocomplete="off" class="layui-input" placeholder="请输入账户">
                        </div>
                </div>
                <div class="layui-form-item">
                        <label class="layui-form-label">登陆密码:</label>
                        <div class="layui-input-inline">
                            <input type="password" id="password" name="password" required=""  lay-verify="password" autocomplete="off" class="layui-input" placeholder="请输入密码">
                            <p class="add_titps text-left">随机生成</p>
                        </div>
                </div>
                <div class="layui-form-item">
	              <label  class="layui-form-label"></label>
		          <button  class="layui-btn" lay-filter="add" lay-submit="">确认开通</button>
		        </div>
		        </form>
            </div>
     </div>
     
      <script>
        layui.use(['form','layer','upload'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer,
          upload = layui.upload;
        
        
        
        
        
        
          var uploadInst = upload.render({
			    elem: '.upfile',
			    //url: '/admin/upload/fileupload.htm?module=idcard',
			    
			    done: function(res,index, upload){
			      
			      console.log(res);
			      if(res.code == 1){
			      	 var data = res.data;
			      	 $("#" + this.showImgId + "").attr('src',data.fileurl);
			      	 $("#" + this.inputId + "").val(data.filepath);
			      
			     	 layer.msg('上传成功');
			      }else{
			      	layer.msg('上传失败');
			      }
			      
			      
			    }, error: function(){
			    		layer.msg('上传失败');
			        uploadInst.upload();
			      
			    }
			});
        
        
        
        

          //监听提交
          form.on('submit(add)', function(data){
            console.log(data);
            
            $.ajax({
      			type:"POST", 
      			url:"/admin/company/createAccount.htm",
      			data:data.field ,
      			success:function(result) {
		      
		      		if(result.code=='1'){
		      			var data = result.data;
		      			layer.alert("创建成功", {icon: 6},function () {
		      			
			                location.href="/admin/company/addSuccess.htm?companyId="+data.companyId;
			                
			            });
		      		}else{
		      		 	layer.msg(result.msg);
		      		}
		      
		    	 	} 
		    }); 
            
            return false;
          });
          
        });
    </script>   
     
</body>
</html>